package com.zcp.month2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zcp.month2.R;
import com.zcp.month2.bean.Bean;

import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2017/3/1.
 */

public class GridAdapter extends RecyclerView.Adapter<GridAdapter.GridViewHolder>{
    LayoutInflater inflater;
    List<Bean.RsBean.ChildrenBeanX.ChildrenBean> arr;
    Context context;
    public GridAdapter(Context context, List<Bean.RsBean.ChildrenBeanX.ChildrenBean> arr) {
        this.arr=arr;
        this.inflater=LayoutInflater.from(context);
        this.context=context;
    }

    @Override
    public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.gv_item, parent, false);
        final GridViewHolder gv=new GridViewHolder(view);
        gv.gv_image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = gv.getAdapterPosition();
                Toast.makeText(context,"点击了"+arr.get(position).dirName,Toast.LENGTH_SHORT).show();
            }
        });
        return gv;
    }

    @Override
    public void onBindViewHolder(GridViewHolder holder, int position) {
        x.image().bind(holder.gv_image,arr.get(position).imgApp);
        holder.tv.setText(arr.get(position).dirName);

    }

    @Override
    public int getItemCount() {
        return arr.size();
    }

    class GridViewHolder extends  RecyclerView.ViewHolder
    {

        private final ImageView gv_image;
        private final TextView tv;

        public GridViewHolder(View itemView) {
            super(itemView);
            gv_image = (ImageView) itemView.findViewById(R.id.gv_image);
            tv = (TextView) itemView.findViewById(R.id.gv_name);
        }
    }
}
